package cc.common.manager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ComponentManager implements IManager {

    private ComponentManager() {
    }

    public static ComponentManager getInstance() {
        return InnerClass.manager;
    }

    private Map<String, Object> apiMap = new ConcurrentHashMap<>();

    @Override
    public void register(Class cls, @NonNull Object object) {
        apiMap.put(cls.getName(), object);
    }

    @Override
    public void unregister(Class cls) {
        apiMap.remove(cls.getName());
    }

    @Nullable
    @Override
    public Object get(Class cls) {
        return apiMap.get(cls.getName());
    }

    private static class InnerClass {
        static ComponentManager manager = new ComponentManager();
    }
}
